﻿namespace Eldert.BTUG.IoT.Management.IoTHub.Devices
{
    using System;

    using Libraries.Extensions;

    /// <summary>
    /// Console which will be used to manage our IoT Hub Devices.
    /// </summary>
    public class Program
    {
        /// <summary>
        /// Main method which will start the application.
        /// </summary>
        public static void Main()
        {
            // Device ID used to identify the device
            var deviceID = string.Empty;

            // Get device ID
            while (string.IsNullOrWhiteSpace(deviceID))
            {
                Console.WriteLine("Please specify the ID for your device:");
                deviceID = Console.ReadLine();
            }

            // Create device in IoT hub
            try
            {
                Console.WriteLine($"Your device key: {DeviceManagement.AddDevice(deviceID).Result}");
            }
            catch (Exception exception)
            {
                exception.Log();
            }

            // Wait for key press
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
    }
}
